package com.tanx.cloud;

import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Collections;
import java.util.Enumeration;
import java.util.List;

@RestController
@Slf4j
public class RootController {

    @RequestMapping
    public ResponseEntity entity(HttpServletRequest request) {
        log.info("请求地址{}", request.getRequestURI());
        log.info("=========header=========");
        Enumeration<String> headerNames = request.getHeaderNames();
        while (headerNames.hasMoreElements()) {
            String key = headerNames.nextElement();
            String value = request.getHeader(key);
            log.info("key:{},value:{}", key, value);
        }
        log.info("=========header=========");


        String auth = request.getHeader("auth");
        if (auth != null) {
            return ResponseEntity.ok().header("test", "123").build();
        }
        List<String> list = Collections.singletonList("test");
        JsonResult build = JsonResult.builder().status(HttpStatus.UNAUTHORIZED).success(false).message(list).build();
        return ResponseEntity.status(200).header("notAuth", "456").body(build);
    }
}
